<?php
namespace app\home\controller;
use app\home\controller\HomeBasce;
use think\Request;
use think\Db;

class Logintest  extends  HomeBasce
{
    //我的预约
    public function myyuyue()
    {
        return  $this->fetch('my_yuyue');
    }

    //材料清单
    public function mylist()
    {
        return  $this->fetch('my_list');
    }

    //设置
    public  function  shezhi(){
        return  $this->fetch('shezhi');
    }

    //我的装修
    public function my_decoration(Request $request)
    {
        $uid = session('uid');
//        dump($uid);
//        exit();
        if ($request->isAjax()){

            $page = input('page') ? input('page') : 1;
            $limit = input('limit') ? input('limit') : 5;
            $data_user = Db::name('project_client')->where('user_id',$uid)->find();

            $project_id = $data_user['project_id'];



            $data_stage = Db::name('project_stage')->where('project_id',$project_id)->page($page, $limit)->select();
            $data_project = Db::name('project')->where('id',$project_id)->find();
            $data_stage['project_picture'] = $data_project['project_picture'];

            //七牛域名
            $qiniu_config = cmf_get_option('qiniu');
            // 七牛样式处理
            $q_thumb = "?imageMogr2/auto-orient/thumbnail/!60x120r/gravity/Center/crop/60x60/quality/100/interlace/0";
//        $res['release_time'] = date('Y-m-d ', $res['release_time']);
            $data_stage['project_picture'] = $qiniu_config['domain'] . '/' . $data_stage['project_picture'].$q_thumb ;

            return json(['code' => 1, 'msg' => 'ok', 'count' => count($data_stage), 'data' => $data_stage]);
        }

        return  $this->fetch('my_decoration');
    }

    //我的装修评价
    public function my_decoration_detail(Request $request){


        $uid = session('uid');
        //dump($id);
        if ($request->isAjax()){
            //获取该阶段id
            $id=$request->param("id");
            if (!$id) {
                $this->error('id 异常');
            }



            $appraise_star=$request->param("text");
            $appraise_content = $request->param("content");


            $res = Db::name('project_appraise')
                ->insert(['appraise_star'=>$appraise_star,'appraise_content'=>$appraise_content,'stage_id'=>$id,]);
            if ($res === false) {
                $this->success('操作失败');
            }
            $this->success('操作成功');

        }
        else{
            return $this->fetch('my_decoration_detail');
        }

    }
}